{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1 , user-scalable=no">
<title>比赛场地查询</title>
<link href="{% static 'plugins/bootstrap.css' %}" rel="stylesheet">
<link href="{% static 'plugins/bootstrap-dashen.css' %}" rel="stylesheet">
<link href="{% static 'plugins/font-awesome.css' %}" rel="stylesheet">
<link href="{% static 'plugins/animate.css' %}" rel="stylesheet">
<link href="{% static 'plugins/bootstrap-datetimepicker.min.css' %}" rel="stylesheet" media="screen">
</head>
<body style="margin-top:70px;">
<div class="container">
{% include 'header.html' %}
	<div class="col-md-3 wow fadeInLeft">
		<div class="page-header">
    		<h1>比赛场地查询</h1>
		</div>
		<form name="contestPlaceQueryForm" id="contestPlaceQueryForm" action="{% url 'ContestPlace:frontList' %}" class="mar_t15" method="post">
			 {% csrf_token %}
			<div class="form-group">
				<label for="placeNo">场地编号:</label>
				<input type="text" id="placeNo" name="placeNo" value="{{ placeNo }}" class="form-control" placeholder="请输入场地编号">
			</div>
            <div class="form-group">
            	<label for="contestItemObj_classId">运动项目：</label>
                <select id="contestItemObj_classId" name="contestItemObj.classId" class="form-control">
                	<option value="0">不限制</option>
                    {% for contestItem in contestItems %}
                        {% if contestItem.classId == contestItemObj_classId %}
                             <option value="{{contestItem.classId }}" selected>{{ contestItem.className }}</option>
                        {% else %}
                            <option value="{{ contestItem.classId }}">{{ contestItem.className }}</option>
                        {% endif %}
	 				{% endfor %}
 			</select>
            </div>
			<div class="form-group">
				<label for="placeName">场地名称:</label>
				<input type="text" id="placeName" name="placeName" value="{{ placeName }}" class="form-control" placeholder="请输入场地名称">
			</div>
			<div class="form-group">
				<label for="useDate">投入使用时间:</label>
				<input type="text" id="useDate" name="useDate" class="form-control"  placeholder="请选择投入使用时间" value="{{ useDate }}" onclick="SelectDate(this,'yyyy-MM-dd')" />
			</div>
            <input type=hidden name=currentPage value="{{ currentPage }}" />
            <button type="submit" class="btn btn-primary">查询</button>
        </form>
	</div>

	<div class="col-md-9 wow fadeInRight">
		<ul class="breadcrumb">
  			<li><a href="{% url 'Index:index' %}">首页</a></li>
  			<li><a href="{% url 'ContestPlace:frontList' %}">比赛场地信息列表</a></li>
  			<li class="active">查询结果显示</li>
  			<a class="pull-right" href="{% url 'ContestPlace:frontAdd' %}" style="display:none;">添加比赛场地</a>
		</ul>
		<div class="row">
            {% for contestPlace in contestPlaces_page %}
                {% if forloop.counter|add:-1|divisibleby:4 %}
			<div class="col-md-3 bottom15" style="clear: left;">
                {% else %}
            <div class="col-md-3 bottom15">
                {% endif %}
			  <a  href="{% url 'ContestPlace:frontShow' contestPlace.placeNo %}"><img class="img-responsive" src="{{ contestPlace.placePhoto.url }}" /></a>
			     <div class="showFields">
			     	<div class="field">
	            		场地编号:{{ contestPlace.placeNo }}
			     	</div>
			     	<div class="field">
	            		运动项目:{{ contestPlace.contestItemObj.className }}
			     	</div>
			     	<div class="field">
	            		场地名称:{{ contestPlace.placeName }}
			     	</div>
			     	<div class="field">
	            		场地面积:{{ contestPlace.placeArea }}
			     	</div>
			     	<div class="field">
	            		投入使用时间:{{ contestPlace.useDate }}
			     	</div>
			        <a class="btn btn-primary top5" href="{% url 'ContestPlace:frontShow' contestPlace.placeNo  %}">详情</a>
			        <a class="btn btn-primary top5" onclick="contestPlaceEdit('{{ contestPlace.placeNo }}');" style="display: none;">修改</a>
			        <a class="btn btn-primary top5" onclick="contestPlaceDelete('{{ contestPlace.placeNo }}');" style="display: none;">删除</a>
			     </div>
			</div>
			{% endfor %}

			<div class="row">
				<div class="col-md-12">
					<nav class="pull-left">
						<ul class="pagination">
							<li><a href="#" onclick="GoToPage({{ currentPage|add:-1 }},{{ totalPage }});" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
							{% for page in pageList %}
                                            {% if currentPage == page %}
						                        <li class="active"><a href="#"  onclick="GoToPage({{ page }},{{ totalPage }});">{{ page }}</a></li>
						                    {% else %}
                                                <li><a href="#"  onclick="GoToPage({{ page }},{{ totalPage }});">{{ page }}</a></li>
                                            {% endif %}
                                            {% endfor %}
						                    <li><a href="#" onclick="GoToPage({{ currentPage|add:1 }},{{ totalPage }});"><span aria-hidden="true">&raquo;</span></a></li>
						</ul>
					</nav>
					<div class="pull-right" style="line-height:75px;" >共有{{ recordNumber }}条记录，当前第{{ currentPage }}/{{ totalPage }} 页</div>
				</div>
			</div>
		</div>
	</div>

  </div>
</div>
<div id="contestPlaceEditDialog" class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title"><i class="fa fa-edit"></i>&nbsp;比赛场地信息编辑</h4>
      </div>
      <div class="modal-body" style="height:450px; overflow: scroll;">
      	<form class="form-horizontal" name="contestPlaceEditForm" id="contestPlaceEditForm" enctype="multipart/form-data" method="post"  class="mar_t15">
		    {% csrf_token %}
		  <div class="form-group">
			 <label for="contestPlace_placeNo_edit" class="col-md-3 text-right">场地编号:</label>
			 <div class="col-md-9"> 
			 	<input type="text" id="contestPlace_placeNo_edit" name="contestPlace.placeNo" class="form-control" placeholder="请输入场地编号" readOnly>
			 </div>
		  </div> 
		  <div class="form-group">
		  	 <label for="contestPlace_contestItemObj_classId_edit" class="col-md-3 text-right">运动项目:</label>
		  	 <div class="col-md-9">
			    <select id="contestPlace_contestItemObj_classId_edit" name="contestPlace.contestItemObj.classId" class="form-control">
                    {% for contestItem in contestItems %}
                        <option value="{{ contestItem.classId }}">{{ contestItem.className }}</option>
                    {% endfor %}
			    </select>
		  	 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="contestPlace_placeName_edit" class="col-md-3 text-right">场地名称:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="contestPlace_placeName_edit" name="contestPlace.placeName" class="form-control" placeholder="请输入场地名称">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="contestPlace_placeArea_edit" class="col-md-3 text-right">场地面积:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="contestPlace_placeArea_edit" name="contestPlace.placeArea" class="form-control" placeholder="请输入场地面积">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="contestPlace_placePhoto_edit" class="col-md-3 text-right">场地照片:</label>
		  	 <div class="col-md-9">
			    <img  class="img-responsive" id="contestPlace_placePhotoImg" border="0px"/><br/>
			    <input id="contestPlace_placePhoto" name="contestPlace.placePhoto" type="file" size="50" />
		  	 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="contestPlace_useDate_edit" class="col-md-3 text-right">投入使用时间:</label>
		  	 <div class="col-md-9">
                <div class="input-group date contestPlace_useDate_edit col-md-12" data-link-field="contestPlace_useDate_edit" data-link-format="yyyy-mm-dd">
                    <input class="form-control" id="contestPlace_useDate_edit" name="contestPlace.useDate" size="16" type="text" value="" placeholder="请选择投入使用时间" readonly>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                </div>
		  	 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="contestPlace_placeDesc_edit" class="col-md-3 text-right">场地描述:</label>
		  	 <div class="col-md-9">
			    <textarea id="contestPlace_placeDesc_edit" name="contestPlace.placeDesc" rows="8" class="form-control" placeholder="请输入场地描述"></textarea>
			 </div>
		  </div>
		</form> 
	    <style>#contestPlaceEditForm .form-group {margin-bottom:5px;}  </style>
      </div>
      <div class="modal-footer"> 
      	<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      	<button type="button" class="btn btn-primary" onclick="ajaxContestPlaceModify();">提交</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{% include 'footer.html' %}
<script src="{% static 'plugins/jquery.min.js' %}"></script>
<script src="{% static 'plugins/bootstrap.js' %}"></script>
<script src="{% static 'plugins/wow.min.js' %}"></script>
<script src="{% static 'plugins/bootstrap-datetimepicker.min.js' %}"></script>
<script src="{% static 'plugins/locales/bootstrap-datetimepicker.zh-CN.js' %}"></script>
<script type="text/javascript" src="{% static 'js/jsdate.js' %}"></script>
<script>
/*跳转到查询结果的某页*/
function GoToPage(currentPage,totalPage) {
    if(currentPage==0) return;
    if(currentPage>totalPage) return;
    document.contestPlaceQueryForm.currentPage.value = currentPage;
    document.contestPlaceQueryForm.submit();
}

/*可以直接跳转到某页*/
function changepage(totalPage)
{
    var pageValue=document.contestPlaceQueryForm.pageValue.value;
    if(pageValue>totalPage) {
        alert('你输入的页码超出了总页数!');
        return ;
    }
    document.contestPlaceQueryForm.currentPage.value = pageValue;
    documentcontestPlaceQueryForm.submit();
}

/*弹出修改比赛场地界面并初始化数据*/
function contestPlaceEdit(placeNo) {
	$.ajax({
		url :  '/ContestPlace/update/' + placeNo,
		type : "get",
		dataType: "json",
		success : function (contestPlace, response, status) {
			if (contestPlace) {
				$("#contestPlace_placeNo_edit").val(contestPlace.placeNo);
				$.ajax({
					url: "{% url 'ContestItem:listAll' %}",
					type: "get",
					success: function(contestItems,response,status) { 
						$("#contestPlace_contestItemObj_classId_edit").empty();
						var html="";
		        		$(contestItems).each(function(i,contestItem){
		        			html += "<option value='" + contestItem.classId + "'>" + contestItem.className + "</option>";
		        		});
		        		$("#contestPlace_contestItemObj_classId_edit").html(html);
		        		$("#contestPlace_contestItemObj_classId_edit").val(contestPlace.contestItemObjPri);
					}
				});
				$("#contestPlace_placeName_edit").val(contestPlace.placeName);
				$("#contestPlace_placeArea_edit").val(contestPlace.placeArea);
				$("#contestPlace_placePhotoImg").attr("src", contestPlace.placePhoto);
				$("#contestPlace_useDate_edit").val(contestPlace.useDate);
				$("#contestPlace_placeDesc_edit").val(contestPlace.placeDesc);
				$('#contestPlaceEditDialog').modal('show');
			} else {
				alert("获取信息失败！");
			}
		}
	});
}

/*删除比赛场地信息*/
function contestPlaceDelete(placeNo) {
    var csrf = $('input[name="csrfmiddlewaretoken"]').val();
	if(confirm("确认删除这个记录")) {
		$.ajax({
			type : "POST",
			url : "/ContestPlace/deletes",
			data : {
				placeNos : placeNo,
                "csrfmiddlewaretoken": csrf
			},
			success : function (obj) {
				if (obj.success) {
					alert("删除成功");
					$("#contestPlaceQueryForm").submit();
					//location.href= basePath + "ContestPlace/frontlist";
				}
				else 
					alert(obj.message);
			},
		});
	}
}

/*ajax方式提交比赛场地信息表单给服务器端修改*/
function ajaxContestPlaceModify() {
	$.ajax({
		url :   '/ContestPlace/update/' + $("#contestPlace_placeNo_edit").val(),
		type : "post",
		dataType: "json",
		data: new FormData($("#contestPlaceEditForm")[0]),
		success : function (obj, response, status) {
            if(obj.success){
                alert("信息修改成功！");
                $("#contestPlaceQueryForm").submit();
            }else{
                alert(obj.message);
            } 
		},
		processData: false,
		contentType: false,
	});
}

$(function(){
	/*小屏幕导航点击关闭菜单*/
    $('.navbar-collapse a').click(function(){
        $('.navbar-collapse').collapse('hide');
    });
    new WOW().init();

    /*投入使用时间组件*/
    $('.contestPlace_useDate_edit').datetimepicker({
    	language:  'zh-CN',  //语言
    	format: 'yyyy-mm-dd',
    	minView: 2,
    	weekStart: 1,
    	todayBtn:  1,
    	autoclose: 1,
    	minuteStep: 1,
    	todayHighlight: 1,
    	startView: 2,
    	forceParse: 0
    });
})
</script>
</body>
</html>

